home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 39 / Amiga Format CD39 (1999-04-13)(Future Publishing)(GB)[!][issue 1999-05].iso / -seriously_amiga- / wb / upd_newicon_v1.2 / source / updatenewicon.c < prev    next >
C/C++ Source or Header  |  1999-02-22  |  7KB  |  248 lines

  1. /*********************************************/
  2. /*                                           */
  3. /*       Designer (C) Ian OConnor 1994       */
  4. /*                                           */
  5. /*      Designer Produced C include file     */
  6. /*                                           */
  7. /*********************************************/
  8.  
  9. #include <exec/types.h>
  10. #include <exec/memory.h>
  11. #include <dos/dosextens.h>
  12. #include <intuition/screens.h>
  13. #include <intuition/intuition.h>
  14. #include <intuition/gadgetclass.h>
  15. #include <libraries/gadtools.h>
  16. #include <diskfont/diskfont.h>
  17. #include <utility/utility.h>
  18. #include <graphics/gfxbase.h>
  19. #include <workbench/workbench.h>
  20. #include <graphics/scale.h>
  21. #include <clib/exec_protos.h>
  22. #include <clib/wb_protos.h>
  23. #include <clib/intuition_protos.h>
  24. #include <clib/gadtools_protos.h>
  25. #include <clib/graphics_protos.h>
  26. #include <clib/utility_protos.h>
  27. #include <string.h>
  28. #include <clib/diskfont_protos.h>
  29.  
  30. #include "UpdateNewIcon.h"
  31.  
  32.  
  33. ULONG BevelTags[] =
  34.     {
  35.     (GTBB_Recessed), TRUE,
  36.     (GT_VisualInfo), 0,
  37.     (TAG_DONE)
  38.     };
  39.  
  40. struct IntuiText IconDisplayTexts[] =
  41.     {
  42.     2, 3, JAM1, 214, 8, &topaz801, (UBYTE *)"Options", &IconDisplayTexts[1],
  43.     2, 3, JAM1, 11, 8, &topaz801, (UBYTE *)"Source", &IconDisplayTexts[2],
  44.     2, 3, JAM1, 115, 8, &topaz801, (UBYTE *)"Dest", NULL
  45.     };
  46.  
  47. struct Window *IconDisplay = NULL;
  48. APTR IconDisplayVisualInfo;
  49. APTR IconDisplayDrawInfo;
  50. struct AppWindow *IconDisplayAppWin = NULL;
  51. struct Gadget *IconDisplayGList;
  52. struct Gadget *IconDisplayGadgets[4];
  53. UBYTE IconDisplayFirstRun = 0;
  54.  
  55. ULONG IconDisplayGadgetTags[] =
  56.     {
  57.     (GTCB_Checked), TRUE,
  58.     (TAG_END),
  59.     (GTCB_Checked), TRUE,
  60.     (TAG_END),
  61.     };
  62.  
  63. UWORD IconDisplayGadgetTypes[] =
  64.     {
  65.     CHECKBOX_KIND,
  66.     CHECKBOX_KIND,
  67.     BUTTON_KIND,
  68.     CHECKBOX_KIND,
  69.     };
  70.  
  71. struct NewGadget IconDisplayNewGadgets[] =
  72.     {
  73.     211, 18, 26, 11, (UBYTE *)"Copy NewIcon", &topaz800, IconDisplay_NICopy, 2, NULL,  (APTR)&IconDisplayGadgetTags[0],
  74.     211, 32, 26, 11, (UBYTE *)"Copy Old Icon", &topaz800, IconDisplay_CopyNormal, 2, NULL,  (APTR)&IconDisplayGadgetTags[3],
  75.     211, 101, 142, 15, (UBYTE *)"Help", &topaz800, IconDisplay_Help, 16, NULL,  NULL,
  76.     211, 46, 26, 11, (UBYTE *)"Verbose", &topaz800, IconDisplay_Verbose, 2, NULL,  NULL,
  77.     };
  78.  
  79. struct Library *DiskfontBase = NULL;
  80. struct Library *GadToolsBase = NULL;
  81. struct GfxBase *GfxBase = NULL;
  82. struct IntuitionBase *IntuitionBase = NULL;
  83. struct LocaleBase *LocaleBase = NULL;
  84.  
  85. struct TextAttr topaz801 = { (STRPTR)"topaz.font", 8, 0, 1 };
  86. struct TextAttr topaz800 = { (STRPTR)"topaz.font", 8, 0, 0 };
  87.  
  88. void RendWindowIconDisplay( struct Window *Win, void *vi )
  89. {
  90. int loop;
  91. UWORD offx = Win->BorderLeft;
  92. UWORD offy = Win->BorderTop;
  93. if (Win != NULL)
  94.     {
  95.     BevelTags[3] = (ULONG)vi;
  96.     DrawBevelBoxA( Win->RPort, 7+offx,18+offy,100,98, (struct TagItem *)(&BevelTags[2]));
  97.     DrawBevelBoxA( Win->RPort, 109+offx,18+offy,100,98, (struct TagItem *)(&BevelTags[2]));
  98.     DrawBevelBoxA( Win->RPort, 2+offx,2+offy,354,118, (struct TagItem *)(&BevelTags[0]));
  99.     for( loop=0; loop<3; loop++)
  100.         if (IconDisplayTexts[loop].ITextFont==NULL)
  101.             IconDisplayTexts[loop].ITextFont=Win->WScreen->Font;
  102.     PrintIText( Win->RPort, IconDisplayTexts, offx, offy);
  103.     }
  104. }
  105.  
  106. int OpenWindowIconDisplay( struct MsgPort *awmp, long awid)
  107. {
  108. struct Screen *Scr;
  109. UWORD offx, offy;
  110. UWORD loop;
  111. struct NewGadget newgad;
  112. struct Gadget *Gad;
  113. struct Gadget *Gad2;
  114. APTR Cla;
  115. if (IconDisplayFirstRun == 0)
  116.     {
  117.     IconDisplayFirstRun = 1;
  118.     }
  119. if (IconDisplay == NULL)
  120.     {
  121.     Scr = LockPubScreen(NULL);
  122.     if (NULL != Scr)
  123.         {
  124.         offx = Scr->WBorLeft;
  125.         offy = Scr->WBorTop + Scr->Font->ta_YSize+1;
  126.         if (NULL != ( IconDisplayVisualInfo = GetVisualInfoA( Scr, NULL)))
  127.             {
  128.             if (NULL != ( IconDisplayDrawInfo = GetScreenDrawInfo( Scr)))
  129.                 {
  130.                 IconDisplayGList = NULL;
  131.                 Gad = CreateContext( &IconDisplayGList);
  132.                 for ( loop=0 ; loop<4 ; loop++ )
  133.                     if (IconDisplayGadgetTypes[loop] != 198)
  134.                         {
  135.                         CopyMem((char * )&IconDisplayNewGadgets[loop], ( char * )&newgad, (long)sizeof( struct NewGadget ));
  136.                         newgad.ng_VisualInfo = IconDisplayVisualInfo;
  137.                         newgad.ng_LeftEdge += offx;
  138.                         newgad.ng_TopEdge += offy;
  139.                         IconDisplayGadgets[ loop ] = NULL;
  140.                         IconDisplayGadgets[ newgad.ng_GadgetID - IconDisplayFirstID ] = Gad = CreateGadgetA( IconDisplayGadgetTypes[loop], Gad, &newgad, newgad.ng_UserData );
  141.                         }
  142.                 for ( loop=0 ; loop<4 ; loop++ )
  143.                     if (IconDisplayGadgetTypes[loop] == 198)
  144.                         {
  145.                         IconDisplayGadgets[ loop ] = NULL;
  146.                         Cla = NULL;
  147.                         if (Gad)
  148.                             IconDisplayGadgets[ loop ] = Gad2 = (struct Gadget *) NewObjectA( (struct IClass *)Cla, IconDisplayNewGadgets[ loop ].ng_GadgetText, IconDisplayNewGadgets[ loop ].ng_UserData );
  149.                         }
  150.                 if (Gad != NULL)
  151.                     {
  152.                     if (NULL != (IconDisplay = OpenWindowTags( NULL, (WA_Left), 361,
  153.                                     (WA_Top), 101,
  154.                                     (WA_Width), 362+offx,
  155.                                     (WA_Height), 124+offy,
  156.                                     (WA_Title), "UpdateNewIcon - By Dominic Clifton",
  157.                                     (WA_MinWidth), 150,
  158.                                     (WA_MinHeight), 25,
  159.                                     (WA_MaxWidth), 1200,
  160.                                     (WA_MaxHeight), 1200,
  161.                                     (WA_DragBar), TRUE,
  162.                                     (WA_DepthGadget), TRUE,
  163.                                     (WA_CloseGadget), TRUE,
  164.                                     (WA_Activate), TRUE,
  165.                                     (WA_Dummy+0x30), TRUE,
  166.                                     (WA_SmartRefresh), TRUE,
  167.                                     (WA_AutoAdjust), TRUE,
  168.                                     (WA_Gadgets), IconDisplayGList,
  169.                                     (WA_IDCMP),588,
  170.                                     (TAG_END))))
  171.                         {
  172.                         IconDisplayAppWin = AddAppWindowA( awid, 0, IconDisplay, awmp, NULL);
  173.                         RendWindowIconDisplay(IconDisplay, IconDisplayVisualInfo );
  174.                         GT_RefreshWindow( IconDisplay, NULL);
  175.                         RefreshGList( IconDisplayGList, IconDisplay, NULL, ~0);
  176.                         UnlockPubScreen( NULL, Scr);
  177.                         return( 0L );
  178.                         }
  179.                     }
  180.                 FreeGadgets( IconDisplayGList);
  181.                 FreeScreenDrawInfo( Scr, IconDisplayDrawInfo );
  182.                 }
  183.             FreeVisualInfo( IconDisplayVisualInfo );
  184.             }
  185.         UnlockPubScreen( NULL, Scr);
  186.         }
  187.     }
  188. else
  189.     {
  190.     WindowToFront(IconDisplay);
  191.     ActivateWindow(IconDisplay);
  192.     return( 0L );
  193.     }
  194. return( 1L );
  195. }
  196.  
  197. void CloseWindowIconDisplay( void )
  198. {
  199. if (IconDisplay != NULL)
  200.     {
  201.     if (NULL !=  IconDisplayAppWin )
  202.         RemoveAppWindow( IconDisplayAppWin );
  203.     FreeScreenDrawInfo( IconDisplay->WScreen, IconDisplayDrawInfo );
  204.     IconDisplayDrawInfo = NULL;
  205.     CloseWindow( IconDisplay);
  206.     IconDisplay = NULL;
  207.     FreeVisualInfo( IconDisplayVisualInfo);
  208.     FreeGadgets( IconDisplayGList);
  209.     }
  210. }
  211.  
  212. int OpenLibs( void )
  213. {
  214. LocaleBase = (struct LocaleBase * )OpenLibrary((UBYTE *)"locale.library", 38);
  215. if ( NULL != (DiskfontBase = OpenLibrary((UBYTE *)"diskfont.library" , 36)))
  216.     if ( NULL != (GadToolsBase = OpenLibrary((UBYTE *)"gadtools.library" , 37)))
  217.         if ( NULL != (GfxBase = (struct GfxBase * )OpenLibrary((UBYTE *)"graphics.library" , 37)))
  218.             if ( NULL != (IntuitionBase = (struct IntuitionBase * )OpenLibrary((UBYTE *)"intuition.library" , 37)))
  219.                 return( 0L );
  220. CloseLibs();
  221. return( 1L );
  222. }
  223.  
  224. void CloseLibs( void )
  225. {
  226. if (NULL != DiskfontBase )
  227.     CloseLibrary( DiskfontBase );
  228. if (NULL != GadToolsBase )
  229.     CloseLibrary( GadToolsBase );
  230. if (NULL != GfxBase )
  231.     CloseLibrary( ( struct Library * )GfxBase );
  232. if (NULL != IntuitionBase )
  233.     CloseLibrary( ( struct Library * )IntuitionBase );
  234. if (NULL != LocaleBase )
  235.     CloseLibrary( ( struct Library * )LocaleBase );
  236. }
  237.  
  238. int OpenDiskFonts( void )
  239. {
  240.     int OKSoFar = 0;
  241. if (NULL == OpenDiskFont( &topaz801 ) )
  242.     OKSoFar = 1;
  243. if (NULL == OpenDiskFont( &topaz800 ) )
  244.     OKSoFar = 1;
  245. return ( OKSoFar );
  246. }
  247.  
  248.